package com.cf.r944_ak;

import java.io.*;
import java.util.*;

public class g {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(System.out);

        in.nextToken();
        int t = (int) in.nval;
        while (t-- > 0) {
            in.nextToken(); int n = (int) in.nval;
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                in.nextToken();
                a[i] = (int) in.nval;
            }
            Map<Integer, List<Integer>> posMap = new HashMap<>();
            Map<Integer, List<Integer>> valMap = new HashMap<>();
            for (int i = 0; i < n; i++) {
                int g = a[i] >>> 2;
                posMap.computeIfAbsent(g, k -> new ArrayList<>()).add(i);
                valMap.computeIfAbsent(g, k -> new ArrayList<>()).add(a[i]);
            }
            for (int g : posMap.keySet()) {
                List<Integer> positions = posMap.get(g);
                List<Integer> values = valMap.get(g);

                Collections.sort(positions);
                Collections.sort(values);

                for (int k = 0; k < positions.size(); k++) {
                    a[positions.get(k)] = values.get(k);
                }
            }
            for (int x : a) {
                out.print(x + " ");
            }
            out.println();
        }
        out.flush();
        out.close();
        br.close();
    }

    public static int find(long[] a, long d) {
        int ans = 0;
        int l = 0;
        int r = a.length - 1;

        while (l <= r) {
            int mid = (l + r) / 2;
            if (a[mid] <= d) {
                ans = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }

        return ans;
    }
}
